<div id="podetailContainer">
<ul id="pagination-flickr">
<li class="next">
	<a id="previous_{$intPage}" href="javascript:void(0);"
	class ="paging_ajax"
	> Previous</a>
</li>
{foreach from=$arrPaging item =item}
	{if $item != null}
		<li><a href="javascript:void(0);" id="paging_{$item}"
		{if $intPage == $item}
			class="active"
		{/if}
		class ="paging_ajax" >{$item}</a></li>
	{/if}
{/foreach}
<li class="next">
<a id="next_{$intPage}" class ="paging_ajax"
{if $intTotalPage==$intPage}
{/if} href="javascript:void(0);"> Next </a>
</li>
</ul> 
<p align="right" style="margin-bottom:0px;">
 Total records: <b>{$intTotal}</b>&nbsp; - &nbsp; Records on a page: <b>{$intLimit}</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<a href="javascript:hideBlockUI();"><strong>Close</strong></a>
</p>
	{include file="supplier/popup.result.tpl"}
	<input type="hidden" value ="{$supplierId}" id="supplierId"/>
	<input type="hidden" value ="{$intTotalPage}" id="TotalPage"/>
	<input type="hidden" value ="{$intPage}" id="currentPage"/>
</div>

{literal}
  <script type="text/javascript">
    $(".paging_ajax").click(function(){
		 var id = this.id;
		 var pageSplit = id.split("_");
		 var page = pageSplit[1];
		 var bnt =  pageSplit[0]

		 var totalPage = $("#TotalPage").val();
		 var supplierId = $("#supplierId").val();
		 if(bnt =="next")
		 {
		   if(page = totalPage)
		   {
			 page = totalPage;
		   }
		   else
		   {
			 page = parseInt(page) + 1;
		   }
		 }
		 else if(bnt =="previous")
		 {
		   if(page >1)
		   {
			 page = parseInt(page) - 1;
		   }
		   else
		   {
			page = 1;
		   }
		 }
		 
		 $.ajax({
		   url: HOST + "/supplier/popup",
		   data:{supplierId :supplierId, page : page},
		   success:function(data) {
			 $("#podetailContainer").html(data);
		   }
		 });
	});

	$(".delete-ajax").click(function(){
		 var id = this.id;
		 var idSplit = id.split("_");
		 var deleteId = idSplit[1];
		 var answer = confirm("Are you sure delete it?");
		 if(answer)
		 {
			  $.ajax({
			   url: HOST + "/supplier/delete-detail",
			   data:{id : deleteId},
			   success:function(data) {
				loadPage();
			   }
			 });
		 }
	});

	$(".save-ajax-detail").click(function(){
		 var id = this.id;
		 var idSplit = id.split("_");
		 var saveId = idSplit[1];

		 var costItem = $("#cost_item__" + saveId).val();
		 var quantity = $("#quantity__" + saveId).val();
		 var itemTaxAmount = $("#item_tax_amount__" + saveId).val();
		 var supplierId = $("#supplier_id__" + saveId).val();

    	 $.ajax({
			   url: HOST + "/supplier/save-detail",
			   data:{id : saveId, 
					 cost_item : costItem,
					 quantity : quantity,
					 item_tax_amount : itemTaxAmount, 
					 supplier_id : supplierId	
			   },
			   success:function(data) {
					alert("Save success!");
					loadPage();
			   }
			 });
	});

	function loadPage()
	{
	     var page = $("#currentPage").val();
		 var totalPage = $("#TotalPage").val();
		 var supplierId = $("#supplierId").val();		 
		 $.ajax({
		   url: HOST + "/supplier/popup",
		   data:{supplierId :supplierId, page : page},
		   success:function(data) {
			 $("#podetailContainer").html(data);
		   }
		 });
	}
  </script>
{/literal}